package com.ly.hotel.spainterface;

import android.os.Handler;
import android.os.Message;

import com.ly.hotel.common.MyApplication;
import com.ly.hotel.view.floatWindows.ShuaKaFloatWin;

/**
 * Created by ThinkPad on 2018/3/7.
 */

public class NmSwipeCardUtils {
    private OnSwipeCardInterface onSwipeCardListener;
    private boolean threadFlag = false;

    public NmSwipeCardUtils(OnSwipeCardInterface onSwipeCardListener){
        this.onSwipeCardListener = onSwipeCardListener;
    }

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:
                    if(threadFlag){
                        String cardId = MyApplication.getBandNo();
                        onSwipeCardListener.swipeCardListener(cardId);
                        MyApplication.clearBandNo();
                    }
                    threadFlag = false;
                    break;

                default:
                    break;
            }
        }
    };

    public void setOnSwipeFlag(boolean tag){
        this.threadFlag = tag;
    }

    public void initSwipe(){
        this.threadFlag = true;
        ShuaKaFloatWin.showShuakaWin();
        new Thread(){
            @Override
            public void run() {
                MyApplication.clearBandNo();
                while (MyApplication.getBandNo() == "" && threadFlag){
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                ShuaKaFloatWin.hideShuakaWin();
                Message message = new Message();
                message.what = 1;
                handler.sendMessage(message);
            }
        }.start();
    }
}
